/************************************************************************/
/*    author  vinee.han
/*    time    2015/06/08
/*    BNOUOJ                                                                    */
/************************************************************************/

#include <iostream>
#include <queue>
#include <fstream>
#include <algorithm>
#include <stack>
using namespace std;

int row,col;
int cnt = 0;
char arr[301][301];
bool visted[301][301];
int step[2][2] = {{-1,0},{0,1}};

void fcino()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}

void fexit()
{
	fclose(stdin);
	fclose(stdout);
}

struct point
{
	//int prerow,precol;
	int row,col;
};

stack<point> st;

void dfs(point temp)
{
    point tp;
	tp.row = temp.row+step[0][0];
	tp.col = temp.col+step[0][1];
	if (tp.row < 0 || tp.row >= row || tp.col < 0 || tp.col >= col || arr[tp.row][tp.col] == '*')
	{
		tp.row = temp.row-step[0][0];
		tp.col = temp.col-step[0][1];
		return;
	}
	if (arr[tp.row][tp.col] == 'T')
	{
		cnt++;
		cout<<tp.row<<"     "<<tp.col<<endl;
		return;
	}
	dfs(tp);
	tp.row = temp.row+step[1][0];
	tp.col = temp.col+step[1][1];
	dfs(tp);
}

int main()
{
	fcino();
	int sx,sy,tx,ty;
	cin>>row>>col;
	for (int i=0;i<row;i++)
	{
		for (int j=0;j<col;j++)
		{
			visted[i][j] = false;
		}
	}
	char ch;
	point p;
	for (int i=0;i<row;i++)
	{
		for (int j=0;j<col;j++)
		{
			cin>>ch;
			arr[i][j] = ch;
			if(ch == 'S')
			{
				p.row = i;
				p.col = j;
			}
			if (ch == 'T')
			{
				tx = i;
				ty = j;
			}
		}
	}
	dfs(p);
	cout<<cnt<<endl;
	fexit();
	return 0;
}